import requests,os,webbrowser
print("Python 开发环境配置向导 v1.0")

# Python配置

download = {
    "3.9.4":"https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe",
    "3.9.5":"https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe",
    "3.9.6":"https://www.python.org/ftp/python/3.9.6/python-3.9.6-amd64.exe",
    "3.9.7":"https://www.python.org/ftp/python/3.9.7/python-3.9.7-amd64.exe",
    "3.8.10":"https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.exe"
}

for i in range(download.keys):
    print("Python {i}")

pyver = input("请选择要安装的Python版本:")



if pyver in download.keys:
    print("开始下载 Python {pyver}")
    url = download[pyver]
    headers = {
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.52"
        }
    pythonexe = requests.get(url, headers=headers)
    with open("python_installer.exe", "wb")as downloadfile:
        downloadfile.write(pythonexe)
        print("下载完成,请在打开的窗口中配置Python的安装")
        os.system(".\\python_installer.exe")

print("IDE/编辑器 安装")

downloadE = {
    "PyCharm":"https://download.jetbrains.com.cn/python/pycharm-community-2021.2.2.exe",
    "Intellij idea":"https://download.jetbrains.com.cn/idea/ideaIC-2021.2.2.exe",
    "Visual Studio 2019":"https://visualstudio.microsoft.com/zh-hans/vs/",
    "Visual Studio Code":"https://vscode.cdn.azure.cn/stable/83bd43bc519d15e50c4272c6cf5c1479df196a4d/VSCodeSetup-x64-1.60.1.exe",
    "gVim":"https://github.com/vim/vim-win32-installer/releases/download/v8.2.2825/gvim_8.2.2825_x86_signed.exe"
}

id_ = input("请选择要安装的IDE/编辑器:")

if id_ == "Visual Studio 2019":
    print("请自行下载")
    webbrowser.open(downloadE[id_])

else:
    print("开始下载")
    url = downloadE[id_]
    soft = requests.get(url, headers=headers)
    with open("download_temp.exe", "wb") as e:
        e.write(soft)
        print("下载完成,请在打开的窗口中配置 IDE/编辑器 的安装")
        os.system(".\\download_temp.exe")

print("配置完成，下面，开始开发吧！")
os.system("del python_installer.exe")
os.system("del download_temp.exe")
os.system("pause")